package com.fuhao.ack.comfirm;

import com.fuhao.utils.RabbitUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * ck消息确认机制之comfirm模式的批量模式
 * 定期定量的获取一批消息是否发送成功，若有一条不成功，全部重发
 * @author zhang
 */
public class Product2 {
    public static void main(String[] args) throws IOException, TimeoutException, InterruptedException {
        Connection connection = RabbitUtils.getConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare("ack_comfirm_batch_queue",true,false,false,null);

        channel.confirmSelect();
        for (int i = 0;i < 10;i++){
            String msg = "comfirm批量模式发送消息:"+i;
            channel.basicPublish("","ack_comfirm_batch_queue",null,msg.getBytes());
        }
        if( !channel.waitForConfirms()){
            System.out.println("发送失败");
        }else {
            System.out.println("发送成功");
        }

        channel.close();
        connection.close();
    }
}
